Skip to content

feat: view human-readable database size and v2 route for DBsize#130

Merged
williamrusdyputra merged 1 commit intomainfrom
newDbSize
Oct 3, 2025
Merged

feat: view human-readable database size and v2 route for DBsize#130
williamrusdyputra merged 1 commit intomainfrom
newDbSize

Conversation

@MicBun
Copy link
Copy Markdown
Member

@MicBun MicBun commented Oct 3, 2025

Change the action route for getDatabaseSize() to v2 route and adds getDatabaseSizePretty() method to the Action class, enabling clients to retrieve database size in a user-friendly format (e.g., "22 GB", "1.5 TB") instead of raw byte counts.

This complements the existing getDatabaseSize() method by providing a more accessible view of database storage metrics for end users and dashboards.

resolves: https://github.com/trufnetwork/truf-network/issues/1219

related file: https://github.com/trufnetwork/node/blob/main/internal/migrations/024-get-database-size-v2.sql

Summary by CodeRabbit

  • New Features

    • Introduced a human-readable database size output that returns values like “123 MB” for easier interpretation.
    • Existing numeric database size retrieval remains available; no breaking changes for current integrations.
  • Tests

    • Added integration test to validate the human-readable database size format, ensuring it returns a string with correct numeric value and unit (bytes, kB, MB, GB, TB).

Change the action route for `getDatabaseSize()` to v2 route and adds `getDatabaseSizePretty()` method to the Action class, enabling clients
to retrieve database size in a user-friendly format (e.g., "22 GB", "1.5 TB")
instead of raw byte counts.

This complements the existing `getDatabaseSize()` method by providing a
more accessible view of database storage metrics for end users and
dashboards.

resolves: trufnetwork/truf-network#1219
@MicBun MicBun self-assigned this Oct 3, 2025
@MicBun MicBun added the enhancement New feature or request label Oct 3, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Updates the Action class to use the v2 database size endpoint and adds a new method to fetch a human-readable size. Corresponding integration test added to validate the pretty-printed size format. No other files changed.

Changes

Cohort / File(s) Summary
Contracts API updates
src/contracts-api/action.ts
Switches getDatabaseSize to call "get_database_size_v2". Adds public method getDatabaseSizePretty() calling "get_database_size_v2_pretty" and returning the first row’s database_size_pretty string.
Integration tests
tests/integration/databaseSize.test.ts
Adds test verifying getDatabaseSizePretty returns a truthy string matching a numeric value with unit (bytes, kB, MB, GB, TB).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant A as Action
  participant S as Contracts API

  rect rgba(200,220,255,0.25)
  note over C,A: Get raw database size (v2)
  C->>A: getDatabaseSize()
  A->>S: call "get_database_size_v2"
  S-->>A: rows[{ database_size }]
  A-->>C: number (database_size)
  end

  rect rgba(220,255,220,0.25)
  note over C,A: Get pretty database size (new)
  C->>A: getDatabaseSizePretty()
  A->>S: call "get_database_size_v2_pretty"
  S-->>A: rows[{ database_size_pretty }]
  A-->>C: string (e.g., "123 MB")
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A nibble of numbers, a byte of delight,
I hop to the v2 endpoint—swift as a kite.
Pretty sizes twinkle, MBs in a row,
From raw to readable, watch it glow.
Thump-thump goes my review—tests pass, let’s go! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly indicates the addition of a human-readable database size view alongside the switch to the v2 reporting route, which directly maps to the new getDatabaseSizePretty method and the updated getDatabaseSize endpoint.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch newDbSize

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@holdex
Copy link
Copy Markdown

holdex bot commented Oct 3, 2025

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Oct 3, 2025, 8:48 AM
williamrusdyputra ✅ Submitted 10min Update time Oct 3, 2025, 8:48 AM

@MicBun MicBun changed the title feat: view human-readable database size and v2 route reporting feat: view human-readable database size and v2 route for DBsize Oct 3, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/integration/databaseSize.test.ts (1)

26-37: Consider improving regex pattern strictness and test independence.

The test structure is solid and follows the established pattern. Two minor observations:

  1. Regex pattern: The current pattern /\d+.*\s*(bytes|kB|MB|GB|TB)/i is permissive and could match invalid formats like "123abc GB". Consider a stricter pattern:
-      expect(databaseSizePretty).toMatch(/\d+.*\s*(bytes|kB|MB|GB|TB)/i)
+      expect(databaseSizePretty).toMatch(/^\d+(\.\d+)?\s+(bytes|kB|MB|GB|TB|PB)$/i)

This ensures the format is exactly: number[.decimal] unit (e.g., "22 GB", "1.5 TB")

  1. Test independence: This test relies on the database having data from the first test (which deploys streams). While describe.sequential ensures order, the test would be more robust if it explicitly deployed streams or documented this dependency.

However, if the backend format might vary or include additional text, the lenient regex may be intentional to avoid test brittleness, in which case the current implementation is acceptable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f8462d and d877351.

📒 Files selected for processing (2)
  • src/contracts-api/action.ts (2 hunks)
  • tests/integration/databaseSize.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/integration/databaseSize.test.ts (1)
tests/integration/utils.ts (1)
  • testWithDefaultWallet (9-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/contracts-api/action.ts (2)

949-957: Ensure the pretty-size endpoint exists and handle empty responses

• Confirm the get_database_size_v2_pretty endpoint is implemented and deployed on the backend.
• Add a guard for empty rows to throw a clear, descriptive error (e.g. "No database size data returned").


939-947: Ensure get_database_size_v2 endpoint exists and returns { database_size: BigInt }[]
I couldn’t find an implementation for this RPC in the repo; please verify the backend exposes it and maintains the expected response schema.

@williamrusdyputra williamrusdyputra merged commit 2e1dcae into main Oct 3, 2025
7 of 8 checks passed
@williamrusdyputra williamrusdyputra deleted the newDbSize branch October 3, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants